--created by [SGF] Wrex
local print = print
local include = include
local AddCSLuaFile = AddCSLuaFile





if not USRP then
	USRP = { }
end


USRP.Debug = true
USRP.Version = 8
USRP.CurrentVersion = 0
USRP.Loaded = false






AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile ("help/USRPhelp.lua")
AddCSLuaFile ("hud/hud.lua")
AddCSLuaFile ("menus/employment.lua")
include( 'shared.lua' )

function GetOnlineVersion( printChecking )
	if printChecking then
		print("Checking for updates....")
	end
	http.Get("http://unknown-space-rp.googlecode.com/svn/trunk/","",function(contents,size)
		local rev = tonumber(string.match( contents, "Revision ([0-9]+)" ))
		if rev and USRP.Version >= rev then
			print("Unknown Space RP Is Up To Date, Latest Version: "..rev)
		elseif !rev then
			print("No Internet Connection Detected! Unknown Space RP Update Check Failed")
		else
			print("A newer version of Unknown Space RP is availible! Version: "..rev..", You have Version: "..USRP.Version)
			print("Please update!")
		end
		USRP.CurrentVersion = rev
		
	
	end)
end
GetOnlineVersion()



function USRP.Load()

if Environments then


print("\n*********************U.S.R.P *************************\n")
print("Starting Unknown Space RP, Version: "..USRP.Version.."\n")

if USRP.Debug then
print("\n")
print("DEVELOPING MODE ACTIVE\n")
print("DONT FORGET TO COMMIT CHANGES!!!!\n")
print("\n")
end

print("Loading Core Files..........\n")
print("\n")
include( 'core/rockspawner.lua' )
print("..Loaded Spawning System..\n")
include( 'core/chatsystem.lua' )
print("..Loaded Chat System..\n")
include( 'core/processes.lua' )
print("..Loaded Processes..\n")
include( 'core/resourcesystem.lua' )
print("..Loaded Resources..\n")
include( 'core/skillsystem.lua' )
print("..Loaded Skills..\n")  
print("\n")
print("All Files Loaded!\n")
print("\n")
print("Unknown Space RP Sucessfully Started!\n")
print("\n******************************************************\n")










function GM:ShowHelp( ply ) -- This hook is called everytime F1 is pressed.
    umsg.Start( "HelpMenu", ply ) -- Sending a message to the client.
    umsg.End()
end --Ends function


function GM:PlayerInitialSpawn( ply ) 
	 
     
	 
	 if ply:IsAdmin() then 
	 ply:ChatPrint("You have joined as an Admin")
	 ply:ChatPrint("Welcome to USRP!")
     ply:SetTeam( 10 ) 
	 ply:UnSpectate()
	 ply:Spawn()
	 
	 ply:Resources_Set("credits",10000000)
	 
	 else
	 --ply:ConCommand( "race_selection" )
	 ply:Resources_Set("credits",10000)
	 ply:ChatPrint("Welcome to USRP!")
	 end
	 
 
 end 
 
 function GM:PlayerLoadout(ply) 
 
	ply:StripWeapons() 
 
	--Lumanian loadout (1 - 3)
	if ply:Team() == 1 then

		ply:Give("weapon_physgun")
		
	elseif ply:Team() == 2 then 
		
		ply:Give("weapon_physgun") 
		
	elseif ply:Team() == 3 then 
		
		ply:Give("weapon_physgun") 
	-- Randroid loadout (4 - 6)
	elseif ply:Team() == 4 then

		ply:Give("weapon_physgun")
		
	elseif ply:Team() == 5 then 
		
		ply:Give("weapon_physgun") 
		
	elseif ply:Team() == 6 then 
		
		ply:Give("weapon_physgun") 
	
	elseif ply:Team() == 10 then
	
	ply:Give("weapon_physgun") 
	ply:Give("gmod_tool") 
	ply:Give("weapon_crowbar")
	ply:Give("usrp_pickaxe")
	ply:Give("usrp_hands")

	end 
 
end 
 
 
 -- Lumanian spawns
 function lum_miner( ply ) 
	 ply:ChatPrint("You have joined the Lumanian's as a Miner, Press F1 for help.")
     ply:SetTeam( 1 ) 
	 ply:UnSpectate()
	 ply:Spawn()
 end 
 
 function lum_worker( ply ) 
	 ply:ChatPrint("You have joined the Lumanian's as a Worker, Press F1 for help.")
     ply:SetTeam( 2 ) 
	 ply:UnSpectate()
	 ply:Spawn()
 end 
 
  function lum_builder( ply ) 
	 ply:ChatPrint("You have joined the Lumanian's as a Builder, Press F1 for help.")
     ply:SetTeam( 3 ) 
	 ply:UnSpectate()
	 ply:Spawn()
 end 
 
  -- Randroid spawns
 function ran_miner( ply ) 
	 ply:ChatPrint("You have joined the Randroid's as a Miner, Press F1 for help.")
     ply:SetTeam( 4 ) 
	 ply:UnSpectate()
	 ply:Spawn()
 end 
 
 function ran_worker( ply ) 
	 ply:ChatPrint("You have joined the Randroid's as a Worker, Press F1 for help.")
     ply:SetTeam( 5 ) 
	 ply:UnSpectate()
	 ply:Spawn()
 end 
 
  function ran_builder( ply ) 
	 ply:ChatPrint("You have joined the Randroid's as a Builder, Press F1 for help.")
     ply:SetTeam( 6 ) 
	 ply:UnSpectate()
	 ply:Spawn()
 end 
 

 
 
 concommand.Add( "lumanian_miner", lum_miner ) 
 concommand.Add( "lumanian_worker", lum_worker ) 
 concommand.Add( "lumanian_builder", lum_builder ) 
 concommand.Add( "randroid_miner", ran_miner ) 
 concommand.Add( "randroid_worker", ran_worker ) 
 concommand.Add( "randroid_builder", ran_builder ) 
 

function USRP.Forge_Spawn()
    local Guest_Setup2 = ents.Create("usrp_forge")
    Guest_Setup2:SetPos(Vector(8540.5,-10740.6,-10137.1)) -- sets the position
    Guest_Setup2:SetAngles(Angle(-0.3,90,-1.7))
    Guest_Setup2:Spawn() -- spawns the lobby_npc entity
end
hook.Add("InitPostEntity","forge", USRP.Forge_Spawn)


function USRP.TraderNPC_Spawn()
    local  TraderNPC= ents.Create("npc_shop")
     TraderNPC:SetPos(Vector(8676.1,-10737.9,-10134.6)) 
     TraderNPC:SetAngles(Angle(0,83.5,0))
     TraderNPC:Spawn() 
end
hook.Add("InitPostEntity","tradernpc", USRP.TraderNPC_Spawn)



function USRP.Station()
    local  Station= ents.Create("usrp_ship_station")
     Station:SetPos(Vector(8464.7,-10440.9,-10122.2)) 
     Station:SetAngles(Angle(-0.5,179.9,-1.2))
     Station:Spawn() 

end
hook.Add("InitPostEntity","shipstationspawn", USRP.Station)



else 

print("\n**-------------------U.S.R.P ------------------------**\n")
print("\n")
print("Cannot Start Unknown Space RP. Environments Missing\n")
print("Make Sure You Have Environments installed.\n")
print("\n")
print("\n**-------------------U.S.R.P ------------------------**\n")

end

return end
USRP.Load()

USRP.Loaded = true

if USRP.Debug then
	concommand.Add("usrp_reload", USRP.Load) --reloads everything, mainly for dev'ing
	
	end
	
	
	
	
hook.Add("GetGameDescription", "USRPStatus", function() 

			return "UnknownSpaceRP v"..USRP.Version..""
		
	end)